﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;

namespace QLTV.Forms.KhaiBao
{
    public partial class frmTrainingCrew : BaseForm
    {
        public frmTrainingCrew()
        {
            InitializeComponent();
            statusDataBar1.addTextChange(gridView1);
            statusDataBar1.AddControlPrint(gridControl1);
        }

        private void frmTrainingCrew_Load(object sender, EventArgs e)
        {
            XtraMessageBox.Show("Dang xay dung...");
            //// TODO: This line of code loads data into the 'dsTraining.tblCrew' table. You can move, or remove it, as needed.
            //this.tblCrewTableAdapter.Fill(this.dsTraining.tblCrew);
            //// TODO: This line of code loads data into the 'dsTraining.tblTrainingCourse' table. You can move, or remove it, as needed.
            //this.tblTrainingCourseTableAdapter.Fill(this.dsTraining.tblTrainingCourse);
            //// TODO: This line of code loads data into the 'dsTraining.tblTrainingCrews' table. You can move, or remove it, as needed.
            //this.tblTrainingCrewsTableAdapter.Fill(this.dsTraining.tblTrainingCrews);

        }

        private void lkTraningCourse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
            {
                using (frmTrainingCourse f = new frmTrainingCourse())
                {
                    f.ShowDialog();
                }
                this.tblTrainingCourseTableAdapter.Fill(this.dsTraining.tblTrainingCourse);
            }
        }

        private void lkCrew_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
            {
                using (frmCrew f = new frmCrew())
                {
                    f.ShowDialog();
                }
                this.tblCrewTableAdapter.Fill(this.dsTraining.tblCrew);
            }
        }

        private void statusDataBar1_NewClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblTrainingCrewsBindingSource.AddNew();
        }

        private void statusDataBar1_UpdateClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblTrainingCrewsBindingSource.EndEdit();
            this.tblTrainingCrewsTableAdapter.Update(dsTraining.tblTrainingCrews);
            this.tblTrainingCrewsTableAdapter.Fill(this.dsTraining.tblTrainingCrews);
            alertControl1.Show(this, rm.GetString("sMessageCaption", myCultureInfo), rm.GetString("sMessageSuccess", myCultureInfo));
        }

        private void statusDataBar1_UndoClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            this.tblTrainingCrewsBindingSource.CancelEdit();
            this.tblTrainingCrewsTableAdapter.Fill(this.dsTraining.tblTrainingCrews);
        }

        private void statusDataBar1_DeleteClick(object sender, StatusDataBar.StatusDataBarArgs e)
        {
            if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    this.tblTrainingCrewsBindingSource.RemoveCurrent();
                    this.tblTrainingCrewsTableAdapter.Update(dsTraining.tblTrainingCrews);
                    this.tblTrainingCrewsTableAdapter.Fill(this.dsTraining.tblTrainingCrews);
                }
                catch (SqlException ex)
                {
                    this.tblTrainingCrewsTableAdapter.Fill(this.dsTraining.tblTrainingCrews);
                    if (ex.ErrorCode == -2146232060)
                    {
                        XtraMessageBox.Show(rm.GetString("sDataInUsed", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        XtraMessageBox.Show(ex.Message, rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
           
        }
    }
}